package wavenotes;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;

public class Util {
	/**
	 * Util method to read a stream of bytes into a byte array.
	 * 
	 * @param in
	 * @return
	 * @throws IOException
	 */
	public static byte[] readStream(InputStream in) throws IOException {
		ByteArrayOutputStream out = new ByteArrayOutputStream();
		final int BUF_SIZE = 1 << 8; //1KiB buffer
		byte[] buffer = new byte[BUF_SIZE];
		int bytesRead = -1;
		while((bytesRead = in.read(buffer)) > -1) {
			  out.write(buffer, 0, bytesRead);
		}
		in.close();
		
		return out.toByteArray();
	}
}
